library(sna)
library(plottrix)
library(cluster)
set.seed(10)
nodes <- 30
type <- runif(nodes) > .5
comm <- sample(1:3,nodes,rep=T)
base <- .035
add <- .75
tprob <- matrix(base,nodes,nodes)
scomm <- as.matrix(dist(comm))==0
tprob <- tprob + add*scomm
net <- rgraph(nodes,tprob=tprob)
xy <- gplot(net)
net <- net*(as.matrix(dist(type))>0)
cents <- matrix(0,3,2)
rads <- numeric(3)
for(i in 1:3){
	xyi <- xy[comm==i,]
	cents[i,] <- apply(xyi,2,mean)
	rads[i] <- 1.25*max(c(dist(xyi)))/2
}

filei <- "/home/bruce/Dropbox/Research/Active/Camp/Tex/CommNet.pdf"
pdf(filei,height=4,width=4,pointsize=10,family="Times")
par(bg="black")	
gplot(net,vertex.col=ifelse(type,"brown3","navy"),coord=xy, gmode="graph", edge.col=rgb(255,255,255,100,maxColorValue=255), vertex.sides=4+100*type, vertex.cex=1.5)
for(i in 1:3){
	draw.circle(cents[i,1],cents[i,2],rads[i],col="cyan3",border="cyan3")
}
gplot(net,vertex.col=ifelse(type,"brown3","navy"),coord=xy, gmode="graph",edge.col=rgb(255,255,255,100,maxColorValue=255), vertex.sides=4+100*type,new=F,vertex.cex=1.5, vertex.border=ifelse(type,"brown3","navy"))
dev.off()

